<?php

class MysqlCommon{
    private $conn;
    public function __construct()
    {
        $this->conn = $this->conn();
    }

    public function conn(){
        $serverName = "127.0.0.1";
        $username = "root";
        $password = "root";

        try {
            $con = new PDO("mysql:host=$serverName;",$username,$password);
            return $con;
        }catch (Exception $e){
            echo "连接失败" . $e->getMessage();
        }finally{
        }
    }

    public function insert($sql){
        $this->conn->exec($sql);
    }

    public function select($sql){
       $res = $this->conn->query($sql);
       return $res->fetchAll(PDO::FETCH_ASSOC);
    }

}
